<?php
	session_start();
	require('game_functions.php');
	$type = $_GET['type'];
	if($type==""){
		$type = $_POST['type'];
	}

	$game = $_POST['game'];
	$vote = $_POST['vote'];
	
	if($vote == '+'){
		$vote = 'Y';
	}else if($vote == '-'){
		$vote = 'N';
	}else if($vote != ''){
		$vote = '?';
	}
	
	
if($game != ''){
dblogin();
	/* check to see if that player has a vote there, and if so, update else insert*/
	$query = "select g.gameid from GAME_VOTE g where g.gameid = '$game' and g.player = ".$_SESSION['USERNUM'];
	$result = mysql_query($query);
	if($row = mysql_fetch_array($result)){
		/* update */
		$query = "update GAME_VOTE g  set vote = '$vote' where g.gameid = '$game' and player = ".$_SESSION['USERNUM'];;
		$result = mysql_query($query);
		$query = "update GAME_VOTE g  set sub_dt = now() where g.gameid = '$game' and player = ".$_SESSION['USERNUM'];;
		$result = mysql_query($query);
	}else{
		/* insert */
		$query = "insert into GAME_VOTE values ($game, ".$_SESSION['USERNUM'].",'$vote',now());";
		$result = mysql_query($query);
	}
}

	update_gamelists();
	show_games($type,1);
?>